"use client";
import { getRegisterApi } from "@/api/user";
import DomainFooter from "@/components/DomainFooter";
import HeaderBack from "@/components/HeaderBack";
import { useRouter } from "@/i18n";
import { Toast } from "antd-mobile";
import { useTranslations } from "next-intl";
import { FC, useState } from "react";
import FromCom from "../login/component/FromCom";
import GoogleCom from "../login/component/GoogleCom";
import "../login/page.scss";

interface Props {}

const Register: FC<Props> = () => {
    const t = useTranslations("LoginPage");
    const router: any = useRouter();
    const [msgError, setMsgError] = useState("");
    const registerRequest = async ({ userPhone, pwd }: any) => {
        let params = { user_phone: userPhone, pwd, code: "123456" };
        let { code, msg } = await getRegisterApi(params);
        if (code == 200) {
            Toast.show({ icon: "success", content: t("registerSuc"), maskClickable: false });
            setTimeout(() => {
                router.replace("/login");
            }, 1000);
        } else {
            setMsgError(msg);
        }
    };
    return (
        <div className="register-box">
            <HeaderBack />
            <GoogleCom title={t("registerGoogletitle")} text={t("registerGoogletext")} />
            <FromCom type="register" callbackFun={registerRequest} msgError={msgError} />
            <DomainFooter />
        </div>
    );
};

export default Register;
